﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbResultExtensionTest and is intended
    ///     to contain all TmdbResultExtensionTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbResultExtensionTest
    {
        [TestMethod]
        public void UnwrapTest()
        {
            var tmdbResult = new TmdbResult<String>
                {
                    Result = Guid.NewGuid().ToString()
                };

            Assert.AreEqual( tmdbResult.Result, tmdbResult.Unwrap() );
        }

        [TestMethod]
        public void UnwrapTest1()
        {
            var tmdbResult = new TmdbResult<String>
                {
                    Result = Guid.NewGuid().ToString(),
                    Error = new ArgumentNullException()
                };

            Assert.IsNull( tmdbResult.Unwrap() );
        }

        [TestMethod]
        public void UnwrapOrThrowTest()
        {
            var tmdbResult = new TmdbResult<String>
                {
                    Result = Guid.NewGuid().ToString()
                };

            Assert.AreEqual( tmdbResult.Result, tmdbResult.UnwrapOrThrow() );
        }

        [TestMethod]
        public void UnwrapOrThrowTest1()
        {
            var tmdbResult = new TmdbResult<String>
                {
                    Result = Guid.NewGuid().ToString(),
                    Error = new ArgumentException(),
                    ApiErrorResponse = new TmdbStatusResponse()
                };

            var exceptionThrown = false;
            try
            {
                tmdbResult.UnwrapOrThrow();
            }
            catch ( TmdbException ex )
            {
                exceptionThrown = true;
                Assert.AreSame( tmdbResult.ApiErrorResponse, ex.ApiError );
                Assert.AreSame( tmdbResult.Error, ex.InnerException );
            }
            Assert.IsTrue( exceptionThrown );
        }
    }
}